import { _decorator } from 'cc';
const { ccclass, property } = _decorator;
import * as fgui from "fairygui-cc";
import { GameController } from '../manager/GameController';

export default class ResultPlayerEntity {
    public node: fgui.GComponent;

    private _energyLabel: fgui.GComponent;
    private _avatar: fgui.GLoader;

    private _selfEnergyLabel: fgui.GComponent;
    private _selfAvatar: fgui.GLoader;

    private _isSelf: fgui.Controller = null;

    constructor(node: fgui.GComponent) {
        this.node = node;
        this._isSelf = this.node.getController('c1');
        this._energyLabel = this.node.getChild('n2').asCom;
        this._avatar = this.node.getChild('n0', fgui.GLoader)
        this._selfEnergyLabel = this.node.getChild('n6').asCom;
        this._selfAvatar = this.node.getChild('n5', fgui.GLoader)
    }

    updateInfo(info: resultInfo) {
        if (info.memberId === GameController.Instance.memberId) {
            this._isSelf.selectedIndex = 1;
            this._selfAvatar.url = null;
            this._selfAvatar.url = info.avatar;
            this._selfEnergyLabel.text = info.shield.toString();
        }
        else {
            this._avatar.url = null;
            this._avatar.url = info.avatar;
            this._energyLabel.text = info.shield.toString();
        }
    }
}